import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:niuniu/common/constant/AppColor.dart';
import 'package:niuniu/common/constant/AppRadius.dart';
import 'package:niuniu/common/constant/AssetsImage.dart';
import 'package:niuniu/common/router/RouteNames.dart';
import 'package:niuniu/pages/my/controller.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';

class MyPage extends GetView<MyController> {
   MyPage({Key? key}) : super(key: key);

  // 用户区
  Widget buildUserZone() {
    return Container(
        padding: EdgeInsets.only(top: 50.h),
        child: GestureDetector(
          child: Row(
            children: [
              Container(
                width: 90.w,
                height: 90.w,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  image:  DecorationImage(
                      image: AssetImage(AssetsImage.defaultPng),
                      fit: BoxFit.cover),
                  borderRadius: BorderRadius.circular(90.w),
                ),
              ),
              SizedBox(width: 15.w),
              Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text("我的昵称", style: TextStyle(fontSize: 16.w, color: AppColor.firstFontColor)),
                  SizedBox(height: 10.w),
                  Text(
                    "搭号：860522616",
                    style: TextStyle(fontSize: 12.w, color: AppColor.secondFontColor),
                  ),
                ],
              ),
              Expanded(child: Container()),
               FaIcon(FontAwesomeIcons.chevronRight, color: Colors.grey)
            ],
          ),
          onTap: () {
            Get.toNamed(RouteNames.personInfo);
          },
        ));
  }

  // vip 区
  Widget buildVipZone() {
    return Container(
      padding: EdgeInsets.all(10.w),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(AppRadius.card),
        color: AppColor.accentColour,

      ),
      // height: 80.h,
      child: GestureDetector(
        child: Row(
          children: [
             Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text("开通VIP会员", style: TextStyle(color: AppColor.firstFontColor),),
                Text("尊享5项专属特权，畅聊无压力", style: TextStyle(color: AppColor.secondFontColor),),
              ],
            ),
            Expanded(child: Container()),
             Text("立即开通", style: TextStyle(color: AppColor.firstFontColor)),
          ],
        ),
        onTap: () {
          Get.toNamed(RouteNames.vip);
        },
      ),
    );
  }

  // 功能区
  Widget buildFunctionZone() {
    return Container(
      alignment: Alignment.center,
      padding: EdgeInsets.all(10.w),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(AppRadius.card),
        color: AppColor.cardBgColor,
      ),
      height: 300.h,
      child: GridView(
          padding:  EdgeInsets.all(4),
          gridDelegate:  SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 3,
          ),
          children: [
            IconButton(
              icon:  Column(children: [
                FaIcon(FontAwesomeIcons.gear, color: AppColor.firstFontColor),
                SizedBox(height: 5),
                Text("demo", style: TextStyle(color: AppColor.firstFontColor)),
              ]),
              onPressed: () {
                Get.toNamed(RouteNames.demo, arguments: {"type": 123});
              },
            ),
            IconButton(
              icon:  Column(children: [
                FaIcon(FontAwesomeIcons.gear, color: AppColor.firstFontColor),
                SizedBox(height: 5),
                Text("登录", style: TextStyle(color: AppColor.firstFontColor)),
              ]),
              onPressed: () {
                Get.toNamed(RouteNames.login);
              },
            ),
            IconButton(
              icon:  Column(children: [
                FaIcon(FontAwesomeIcons.gear, color: AppColor.firstFontColor),
                SizedBox(height: 5),
                Text("设置", style: TextStyle(color: AppColor.firstFontColor)),
              ]),
              onPressed: () {
                Get.toNamed(RouteNames.setting);
              },
            ),
            IconButton(
              icon: Column(children: [
                FaIcon(FontAwesomeIcons.circleHalfStroke,
                    color: AppColor.firstFontColor),
                SizedBox(height: 5),
                Text("主题模式", style: TextStyle(color: AppColor.firstFontColor)),
              ]),
              onPressed: () {
                Get.toNamed(RouteNames.darkPattern);
              },
            ),
            IconButton(
              icon: Column(children: [
                FaIcon(FontAwesomeIcons.screwdriverWrench,
                    color: AppColor.firstFontColor),
                SizedBox(height: 5),
                Text("帮助反馈", style: TextStyle(color: AppColor.firstFontColor)),
              ]),
              onPressed: () {
                Get.toNamed(RouteNames.helpFeedback);
              },
            ),
            IconButton(
              icon:  Column(children: [
                FaIcon(FontAwesomeIcons.headphones,
                    color: AppColor.iconColor),
                SizedBox(height: 5),
                Text("官方客服", style: TextStyle(color: AppColor.firstFontColor)),
              ]),
              onPressed: () {
                Get.toNamed(RouteNames.officialCustomerService);
              },
            )
          ]),
    );
  }

  // 主视图
  Widget buildView() {
    return Container(
      padding: EdgeInsets.only(left: 15.w, right: 15.w),
      child: Column(
        children: [
          // 顶部 APP 导航栏
          buildUserZone(),
          SizedBox(height: 35.h),
          buildVipZone(),
          SizedBox(height: 20.h),
          buildFunctionZone(),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    print(Theme.of(context).brightness == Brightness.light);
    return GetBuilder<MyController>(
      init: MyController(),
      id: "my_page",
      builder: (_) {
        return Scaffold(
          body: SafeArea(child: buildView()),
        );
      },
    );
  }
}
